import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../config/app_theme.dart';
import '../../providers/app_state.dart';

class SettingsScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final appState = Provider.of<AppState>(context);
    
    return Scaffold(
      appBar: AppBar(
        title: Text('设置'),
      ),
      body: ListView(
        children: [
          _buildHeader('账号设置'),
          _buildSettingItem(
            context,
            icon: Icons.person,
            title: '个人资料',
            subtitle: '修改昵称、头像等信息',
            onTap: () {
              ScaffoldMessenger.of(context).showSnackBar(
                SnackBar(content: Text('个人资料功能即将上线')),
              );
            },
          ),
          _buildSettingItem(
            context,
            icon: Icons.lock,
            title: '账号安全',
            subtitle: '修改密码、设置隐私权限',
            onTap: () {
              ScaffoldMessenger.of(context).showSnackBar(
                SnackBar(content: Text('账号安全功能即将上线')),
              );
            },
          ),
          _buildSettingItem(
            context,
            icon: Icons.notifications,
            title: '消息通知',
            subtitle: '设置推送通知方式',
            onTap: () {
              ScaffoldMessenger.of(context).showSnackBar(
                SnackBar(content: Text('消息通知功能即将上线')),
              );
            },
          ),
          
          _buildHeader('应用设置'),
          _buildSettingItem(
            context,
            icon: Icons.brightness_4,
            title: '深色模式',
            trailingWidget: Switch(
              value: appState.isDarkMode,
              onChanged: (value) {
                Provider.of<AppState>(context, listen: false).toggleDarkMode();
              },
              activeColor: AppTheme.primaryColor,
            ),
            onTap: () {
              Provider.of<AppState>(context, listen: false).toggleDarkMode();
            },
          ),
          _buildSettingItem(
            context,
            icon: Icons.data_usage,
            title: '隐私设置',
            subtitle: '管理个人数据和权限',
            onTap: () {
              ScaffoldMessenger.of(context).showSnackBar(
                SnackBar(content: Text('隐私设置功能即将上线')),
              );
            },
          ),
          _buildSettingItem(
            context,
            icon: Icons.language,
            title: '语言',
            subtitle: '简体中文',
            onTap: () {
              ScaffoldMessenger.of(context).showSnackBar(
                SnackBar(content: Text('语言设置功能即将上线')),
              );
            },
          ),
          
          _buildHeader('其他'),
          _buildSettingItem(
            context,
            icon: Icons.help_outline,
            title: '帮助与反馈',
            onTap: () {
              ScaffoldMessenger.of(context).showSnackBar(
                SnackBar(content: Text('帮助与反馈功能即将上线')),
              );
            },
          ),
          _buildSettingItem(
            context,
            icon: Icons.info_outline,
            title: '关于我们',
            onTap: () {
              _showAboutDialog(context);
            },
          ),
          _buildSettingItem(
            context,
            icon: Icons.exit_to_app,
            title: '退出登录',
            onTap: () {
              _showLogoutDialog(context);
            },
          ),
          
          // App版本信息
          Padding(
            padding: const EdgeInsets.all(16.0),
            child: Center(
              child: Text(
                '宠物乐园 v1.0.0',
                style: TextStyle(
                  color: Colors.grey,
                  fontSize: 14,
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildHeader(String title) {
    return Padding(
      padding: const EdgeInsets.fromLTRB(16, 16, 16, 8),
      child: Text(
        title,
        style: TextStyle(
          color: AppTheme.primaryColor,
          fontWeight: FontWeight.bold,
          fontSize: 16,
        ),
      ),
    );
  }

  Widget _buildSettingItem(
    BuildContext context, {
    required IconData icon,
    required String title,
    String? subtitle,
    Widget? trailingWidget,
    required VoidCallback onTap,
  }) {
    return ListTile(
      leading: Icon(icon, color: Colors.grey[700]),
      title: Text(title),
      subtitle: subtitle != null ? Text(subtitle) : null,
      trailing: trailingWidget ?? Icon(Icons.arrow_forward_ios, size: 16),
      onTap: onTap,
    );
  }

  void _showAboutDialog(BuildContext context) {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text('关于宠物乐园'),
          content: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Image.asset(
                'assets/images/logo.png',
                width: 80,
                height: 80,
              ),
              SizedBox(height: 16),
              Text(
                '宠物乐园 v1.0.0',
                style: TextStyle(
                  fontWeight: FontWeight.bold,
                  fontSize: 16,
                ),
              ),
              SizedBox(height: 8),
              Text(
                '宠物乐园是一款专为宠物爱好者设计的社交平台，旨在为宠物爱好者提供一个交流、分享、互助的平台。',
                textAlign: TextAlign.center,
                style: TextStyle(fontSize: 14),
              ),
              SizedBox(height: 16),
              Text(
                '© 2023 宠物乐园团队 保留所有权利',
                style: TextStyle(
                  fontSize: 12,
                  color: Colors.grey,
                ),
              ),
            ],
          ),
          actions: [
            TextButton(
              onPressed: () {
                Navigator.of(context).pop();
              },
              child: Text('关闭'),
            ),
          ],
        );
      },
    );
  }

  void _showLogoutDialog(BuildContext context) {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text('退出登录'),
          content: Text('确定要退出登录吗？'),
          actions: [
            TextButton(
              onPressed: () {
                Navigator.of(context).pop();
              },
              child: Text('取消'),
            ),
            TextButton(
              onPressed: () {
                Provider.of<AppState>(context, listen: false).logout();
                Navigator.of(context).pop();
                Navigator.of(context).pop(); // 返回上一页
                ScaffoldMessenger.of(context).showSnackBar(
                  SnackBar(content: Text('已退出登录')),
                );
              },
              child: Text('确定'),
            ),
          ],
        );
      },
    );
  }
} 